// store/modules/user.js
export default {
  namespaced: true,
  state: () => ({
    userInfo: null
  }),
  mutations: {
    setUser(state, userInfo) {
      state.userInfo = userInfo;
    }
  },
  actions: {
    fetchUser({ commit }) {
      // 模拟异步请求，获取用户信息
      setTimeout(() => {
        const user = { name: 'John Doe', age: 30 };
        commit('setUser', user);
      }, 1000);
    }
  },
  getters: {
    userName: (state) => state.userInfo ? state.userInfo.name : 'Guest'
  }
};
